package com.text.day3_1;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

public class NiHao<E> implements Collection<E> {
    private Object[] objects = null;
    private int count = 0;
    @Override
    public int size() {
        return count;
    }

    @Override
    public boolean isEmpty() {
        return count == 0;
    }

    @Override
    public boolean contains(Object o) {
        for (Object object : objects) {
            if (o.equals(object))
                return true;
        }
        return false;
    }

    @Override
    public Iterator<E> iterator() {

        return new Iterator<E>() {
            @Override
            public boolean hasNext() {
                return false;
            }

            @Override
            public E next() {
                return null;
            }
        };
    }

    @Override
    public Object[] toArray() {

        Object[] o = new Object[count];
        for (int i = 0; i < objects.length; i++) {
            o[i] = objects[i];
        }
        return o;
    }

    @Override
    public <T> T[] toArray(T[] a) {
        T[] o;
        for (int i = 0; i < objects.length; i++) {
//            if (objects[i] instanceof)
//            o[i] = objects[i];   //那个复制不要强转类型？？？？
        }
        return null;
    }

    @Override
    public boolean add(E e) {
        if (objects == null) {
            objects = new Object[1];
            count++;
        } else {
            objects = Arrays.copyOf(objects,objects.length + 1);
            count++;
        }
        objects[objects.length - 1] = e;
        return true;
    }

    @Override
    public boolean remove(Object o) {

        return false;
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        return false;
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return false;
    }

    @Override
    public void clear() {

    }
}
